package com.gwtjs.hbm2xml.hibernate;

import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

public class Helper {
	private static Helper helper = new Helper();

	private Helper() {
	}

	public static Helper getInstance() {
		return helper;
	}

	/**
	 * @param outFile
	 *            输出路径加文件名 path+name
	 * @param propertyFile
	 *            数据库配置属性文件 file path / filename
	 */
	public void generatorHelper(String outFile, String propertyFile,
			List<String> hbms) {

		Element root = new Element("beans", Namespace.NO_NAMESPACE);
		Document doc = new Document(root);
		
		System.out.println("property File: " + propertyFile);

		Format format = Format.getPrettyFormat();
		format.setEncoding("UTF-8");
		format.setIndent("	");

		XMLOutputter out = new XMLOutputter(format);
		try {
			System.out.println(outFile);
			out.output(doc, new FileWriter(outFile));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
